<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>编辑网站信息</title>
<link href="${rc.getContextPath()}/resources/css/common.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/jquery.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/common.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/jquery.validate.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/messages_cn.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/input.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/js/ajaxupload.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/js/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript">
	var base = '${base}';
</script>
<script type="text/javascript" src="${rc.getContextPath()}/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
var base='${base!}';
var siteId='${siteId!}';
function goBack(){
	window.location.href=base+'/site/admin/seedSite.html?siteId='+siteId;
};
function saveSite() {
	var form1 = $("#tableForm");
	form1.submit();
};
function initUploadButton(buttonId){
	var button = $("#"+buttonId);
	var exts = "jpg|png|gif",paths = "|";
	new AjaxUpload(button,
	{   
			action: '${base}/discount/admin/uploadImage.html',   
			name: 'uploadFile',
		onSubmit : function(file, ext)
		{     
       		if ( !RegExp( "\.(?:" + exts + ")$$", "i" ).test(file) ) 
       		{
       			$.dialog.alert("只能上传以下类型：" + exts).zindex();
				return false;
			}          		         
		 	},   
		 	onComplete: function(file, response,statusText)
		 	{   
			var response = jQuery.parseJSON(response);
		 		if(response.status=="error")
			{
		 			$.dialog.alert("上传失败！") ;
			}
			else 
			{
				var res = eval(response);
				if (res.result) {
					$("#codeImg").attr("src","${base}" + response.path);
					$("#codeImg").css("display","block");
					$("#hidImageUrl").val(response.path);
					$("#txtLocalUrl").val(file);
					$.dialog.alert("上传成功！") ;
				} else {
					$.dialog.alert("上传失败，请重试！") ;
				}
			}
		}   
	}); 
};
function myAlert(txt) {
	window.parent.$.dialog({
		lock : true,
		content : txt,
		cancelVal : '确定',
		autoSize : true,
		cancel : function() { //请求成功后处理函数。 
		}
	});
}

/* jQuery.validator.addMethod("validEmailFeedback", function(value, element) {
	var content = $("#txtEmailFeedback").html();
	if(content && content.indexOf("IdentifyCodeToReplace") > -1){
		return true;
	}else{
		return false;
	}
}, "请输入包含IdentifyCodeToReplace的内容，以便替换为真实的验证码供用户进行注册验证"); */

$(document).ready(function() {
	var $inputForm = $("#tableForm");
	$inputForm.validate({
		errorClass : "fieldError",
		rules : {
			cnName : {required:true,maxlength:95},
			enName : {required:true,maxlength:95}/* ,
			emailTitle : {required:true},
			emailFeedback : {required:true,validEmailFeedback:true} */
		}
	});
	initUploadButton('btnUpload');
	var url = "${site.qrCode!}";
	if (!url) {			
		$("#codeImg").css("display","none");//如果没图片，就不显示图片框
	}
});
function show()   

{    
	var html_val = CKEDITOR.instances.ueditTxt.getData();
   var tempForm = document.createElement("form");    

   tempForm.id="tempForm1";    

   tempForm.method="post";    

   tempForm.action="${base!}/front/aboutShow.html";    

   tempForm.target="_blank";    

   var hideInput = document.createElement("input");    

   hideInput.type="hidden";    

   hideInput.name= "html"  

   hideInput.value= encodeURI(html_val);  
   
   tempForm.appendChild(hideInput);   

   document.body.appendChild(tempForm);  
   tempForm.submit();
   document.body.removeChild(tempForm);

}  

</script>
</head>
<body>
	<div class="path">
		<b>编辑网站信息</b>
	</div>
	<form action="${base!}/site/admin/updateSite.html" method="post" id="tableForm" name="tableForm" enctype="multipart/form-data">
		<input type="hidden" name='siteId' value='${siteId!}'/>
		<table class="input tabContent">
			<tbody>
				<tr>
					<th><span class="requiredField">*</span>中文名称:</th>
					<td>
						<input type="text" name="cnName" value="${site.cnName!}"/>
					</td>
					<th><span class="requiredField">*</span>英文名称:</th>
					<td>
						<input type="text" id="address" name="enName" value="${site.enName!}"/>
					</td>
				</tr>
				<tr>
					<th>地址:</th>
					<td>
						<input type="text" name="address" value="${site.address!}"/>
					</td>
					<th>Mail:</th>
					<td>
						<input type="text" name="mail" value="${site.mail!}" id="mail"/>
					</td>
				</tr>				
				<tr>
					<th>二维码:</th>
					<td>
						<input type="text" id='txtLocalUrl' value='${site.qrCode!}'/>
						<input type="hidden" name="qrCode" id="hidImageUrl" value='${site.qrCode!}'/>
						<input type="button" id="btnUpload" value="上传"/>
					</td>
					<th>We Chat:</th>
					<td>
						<input type="text" name="weChat" value="${site.weChat!}" />
					</td>
				</tr>
				<tr>
					<th>此处显示图片:</th>
					<td colspan="3">
						<img src="${site.qrCode!}" alt="" id="codeImg"  width="200" height="200" />
					</td>
				</tr>
				<!-- <tr>
					<th>邮箱验证反馈标题:</th>
					<td><input type="text" name="emailTitle" style="width:500px" value="${site.emailTitle}"/></td>
				</tr>
				<tr>
					<th>邮箱验证反馈内容:</th>
					<td colspan="3">
						<table width="100%">
							<tr align="left">
								<td width="360px">
									<textarea name="emailFeedback" id="txtEmailFeedback" cols="60" rows="6">${site.emailFeedback}</textarea>
								</td>
								<td>
									使用说明：<br />
									例如反馈内容为：您的验证码是：<font color="red">121313</font> <br />
									那么请输入内容：您的验证码是：<font color="red">IdentifyCodeToReplace</font> <br />
									其中：发邮件给用户的时候，IdentifyCodeToReplace会被替换为真实的验证码
								</td>
							</tr>
						</table>
					</td>
				</tr> -->
				<tr>
					<th>简介:</th>
				<td colspan="3">
						<textarea rows="30" cols="50" name="description" id = "ueditTxt" >${site.description!}</textarea>
			            <script type="text/javascript">CKEDITOR.replace('description');</script>
				</td>					
				</tr>
			</tbody>
		</table>

		<table class="input">
			<colgroup>
				<col width="15%" />
				<col width="35%" />
				<col width="15%" />
				<col width="35%" />
			</colgroup>
			<tr>
				<td></td>
				<td colspan="3">
					<input type="button" class="button" value="保存" onclick='saveSite()'/> 
					<input type="button" class="button" value="预览"  onclick="show()"/>
					<input type="button" class="button" value="返回" onclick="goBack()" />
				</td>
			</tr>			
		</table>
	</form>
</body>
</html>